﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TouchSocket.Core;
using TouchSocket.Http.WebSockets;
using TouchSocket.Sockets;

namespace Kang.Test.WPF.FTP
{
    public class FtpCommandLinePlugin : TcpCommandLinePlugin
    {
        private readonly ILog logger;

        public FtpCommandLinePlugin(ILog logger) : base(logger)
        {
            this.ReturnException = true;//表示执行异常的时候，是否返回异常信息
            this.logger = logger;
        }

        /// <summary>
        /// 加法
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public int AddCommand(int a, int b)
        {
            this.logger.Info($"执行{nameof(AddCommand)}");
            return a + b;
        }

        /// <summary>
        /// 乘法，并且获取调用者信息
        /// </summary>
        /// <param name=""></param>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public int MULCommand(ISocketClient socketClient, int a, int b)
        {
            this.logger.Info($"{socketClient.IP}:{socketClient.Port}执行{nameof(MULCommand)}");
            return a * b;
        }

        /// <summary>
        /// 测试异常
        /// </summary>
        /// <exception cref="Exception"></exception>
        public void ExcCommand()
        {
            throw new Exception("我异常了");
        }
    }
}
